package com.soc.web.client.api;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONBoolean;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.soc.web.client.api.markers.Generator;

public class Options extends BaseOptions implements Generator {
	public Options() {
		super();
	}
	
	@Override
	public JavaScriptObject generate() {
		if(optionsObject.size() > 0) {			
			return optionsObject.getJavaScriptObject();
		} else {
			return null;
		}
	}
		
	/**
	 * Forces content type. Can be set to 'image', 'ajax', 'iframe', 'swf' or 'inline'
	 * @see http://fancybox.net/api
	 */
	public void addType(String type) {
		optionsObject.put("type", new JSONString(type));
	}
	
	/**
	 * Space between FancyBox wrapper and content
	 * @see http://fancybox.net/api
	 */
	public void addPadding(int padding) {
		optionsObject.put("padding", new JSONNumber(padding));
	}
	
	/**
	 * When true, transparency of content is changed for elastic transitions
	 * @see http://fancybox.net/api
	 */
	public void addOpacity(boolean opacity) {
		optionsObject.put("opacity", JSONBoolean.getInstance(opacity));
	}
	
	/**
	 * When true, 'overlayShow' is set to 'true' and 'hideOnOverlayClick', 'hideOnContentClick', 'enableEscapeButton', 'showCloseButton' are set to 'false'
	 * @see http://fancybox.net/api
	 */
	public void addModal(boolean modal) {
		optionsObject.put("modal", JSONBoolean.getInstance(modal));
	}
	
	/**
	 * When true, galleries will be cyclic, allowing you to keep pressing next/back.
	 * @see http://fancybox.net/api
	 */
	public void addCyclic(boolean cyclic) {
		optionsObject.put("cyclic", JSONBoolean.getInstance(cyclic));
	}
	
	/**
	 * Set the overflow CSS property to create or hide scrollbars. Can be set to 'auto', 'yes', or 'no'
	 * @see http://fancybox.net/api
	 */
	public void addScrolling(String scrolling) {
		optionsObject.put("scrolling", new JSONString(scrolling));
	}
	
	/**
	 * Width for content types 'iframe' and 'swf'. Also set for inline content if 'autoDimensions' is set to 'false'
	 * @see http://fancybox.net/api
	 */
	public void addWidth(int width) {
		optionsObject.put("width", new JSONNumber(width));
	}
	
	/**
	 * Height for content types 'iframe' and 'swf'. Also set for inline content if 'autoDimensions' is set to 'false'
	 * @see http://fancybox.net/api
	 */
	public void addHeight(int height) {
		optionsObject.put("height", new JSONNumber(height));
	}
	
	/**
	 * If true, FancyBox is scaled to fit in viewport
	 * @see http://fancybox.net/api
	 */
	public void addAutoScale(boolean autoScale) {
		optionsObject.put("autoScale", JSONBoolean.getInstance(autoScale));
	}
	
	/**
	 * For inline and ajax views, resizes the view to the element recieves. Make sure it has dimensions otherwise this will give unexpected results
	 * @see http://fancybox.net/api
	 */
	public void addAutoDimensions(boolean autoDimensions) {
		optionsObject.put("autoDimensions", JSONBoolean.getInstance(autoDimensions));
	}
	
	/**
	 * When true, FancyBox is centered while scrolling page
	 * @see http://fancybox.net/api
	 */
	public void addCenterOnScroll(boolean centerOnScroll) {
		optionsObject.put("centerOnScroll", JSONBoolean.getInstance(centerOnScroll));
	}
	
//	/**
//	 * Ajax options, Note: 'error' and 'success' will be overwritten by FancyBox
//	 * @see http://fancybox.net/api
//	 */
//	public void addAjax(AjaxOptions ajaxOptions) {
//		optionsObject.put("ajax", ajaxOptions);
//	}
//	
	/**
	 * {wmode: 'transparent'}	Params to put on the swf object
	 * @see http://fancybox.net/api
	 */
	public void addSwf(JavaScriptObject swfOptions) {
		optionsObject.put("swf", new JSONObject(swfOptions));
	}
	
	/**
	 * Toggle if clicking the overlay should close FancyBox
	 * @see http://fancybox.net/api
	 */
	public void addHideOnOverlayClick(boolean hideOnOverlayClick) {
		optionsObject.put("hideOnOverlayClick", JSONBoolean.getInstance(hideOnOverlayClick));
	}
	
	/**
	 * Toggle if clicking the content should close FancyBox
	 * @see http://fancybox.net/api
	 */
	public void addHideOnContentClick(boolean hideOnContentClick) {
		optionsObject.put("hideOnContentClick", JSONBoolean.getInstance(hideOnContentClick));
	}
	
	/**
	 * Toggle overlay
	 * @see http://fancybox.net/api
	 */
	public void addOverlayShow(boolean overlayShow) {
		optionsObject.put("overlayShow", JSONBoolean.getInstance(overlayShow));
	}
	
	/**
	 * Opacity of the overlay (from 0 to 1; default - 0.3)
	 * @see http://fancybox.net/api
	 */
	public void addOverlayOpacity(Double overlayOpacity) {
		if(overlayOpacity > 1) {
			overlayOpacity = 1.0;
		} else if(overlayOpacity < 0) {
			overlayOpacity = 0.0;
		}
		optionsObject.put("overlayOpacity", new JSONNumber(overlayOpacity));
	}
	
	/**
	 * '#666'	Color of the overlay
	 * @see http://fancybox.net/api
	 */
	public void addOverlayColor(String overlayColor) {
		optionsObject.put("overlayColor", new JSONString(overlayColor));
	}
	
	/**
	 * Toggle title
	 * @see http://fancybox.net/api
	 */
	public void addTitleShow(boolean titleShow) {
		optionsObject.put("titleShow", JSONBoolean.getInstance(titleShow));
	}
	
	/**
	 * The position of title. Can be set to 'outside', 'inside' or 'over'
	 * @see http://fancybox.net/api
	 */
	public void addTitlePosition(TitlePosition titlePosition) {
		optionsObject.put("titlePosition", new JSONString(titlePosition.toString()));
	}
	
	/**
	 * The transition type. Can be set to 'elastic', 'fade' or 'none'
	 * @see http://fancybox.net/api
	 */
	public void addTransitionIn(Transition transitionIn) {
		optionsObject.put("transitionIn", new JSONString(transitionIn.toString()));
	}
	
	/**
	 * The transition type. Can be set to 'elastic', 'fade' or 'none'
	 * @see http://fancybox.net/api
	 */
	public void addTransitionOut(Transition transitionOut) {
		optionsObject.put("transitionOut", new JSONString(transitionOut.toString()));
	}
	
	
	/**
	 * Speed of the fade and elastic transitions, in milliseconds
	 * @see http://fancybox.net/api
	 */
	public void addSpeedIn(Double speedIn) {
		optionsObject.put("speedIn", new JSONNumber(speedIn));
	}
	
	/**
	 * Speed of the fade and elastic transitions, in milliseconds
	 * @see http://fancybox.net/api
	 */
	public void addSpeedOut(Double speedOut) {
		optionsObject.put("speedOut", new JSONNumber(speedOut));
	}
	
	/**
	 * Speed of resizing when changing gallery items, in milliseconds
	 * @see http://fancybox.net/api
	 */
	public void addChangeSpeed(Double changeSpeed) {
		optionsObject.put("changeSpeed", new JSONNumber(changeSpeed));
	}
	
	/**
	 * Speed of the content fading while changing gallery items
	 * @see http://fancybox.net/api
	 */
	public void addChangeFade(String changeFade) {
		optionsObject.put("changeFade", new JSONString(changeFade));
	}
	
	/**
	 * Easing used for elastic animations
	 * @see http://fancybox.net/api
	 */
	public void addEasingIn(Easing easingIn) {
		optionsObject.put("easingIn", new JSONString(easingIn.toString()));
	}
	
	/**
	 * Easing used for elastic animations
	 * @see http://fancybox.net/api
	 */
	public void addEasingOut(Easing easingOut) {
		optionsObject.put("easingOut", new JSONString(easingOut.toString()));
	}
	
	/**
	 * Toggle close button
	 * @see http://fancybox.net/api
	 */
	public void addShowCloseButton(boolean showCloseButton) {
		optionsObject.put("showCloseButton", JSONBoolean.getInstance(showCloseButton));
	}

	/**
	 * Toggle navigation arrows
	 * @see http://fancybox.net/api
	 */
	public void addShowNavArrows(boolean showNavArrows) {
		optionsObject.put("showNavArrows", JSONBoolean.getInstance(showNavArrows));
	}

	/**
	 * Toggle if pressing Esc button closes FancyBox
	 * @see http://fancybox.net/api
	 */
	public void addEnableEscapeButton(boolean enableEscapeButton) {
		optionsObject.put("enableEscapeButton", JSONBoolean.getInstance(enableEscapeButton));
	}
	
	public enum Easing {
		easeOutBack,
		easeInBack,
		swing
	}
	
	
	public enum Transition {
		fade,
		elastic,
		none
	}
	
	public enum TitlePosition {
		inside,
		outside,
		over
	}
	
}
